package com.akiokevin.plantyourlife.activity;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.akiokevin.plantyourlife.R;

/**
 * Activity displaying and controlling the schedules.
 * 
 * @author Kevin Bang, Akio Akazawa
 *
 */
public class ScheduleActivity extends Activity {
	
	private Button mNewEntryButton;
	private Button mBackButton;
	private ListView mScheduleList;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	    setContentView(R.layout.schedule);
	    
	    // Prepare schedule list
	    mScheduleList = (ListView)findViewById(R.id.list_schedule);
	    // -----------------------
	    // Testing the layout
	    // Only using ArrayList & HashMap to test the layout(SimpleAdapter requires these).
	    // This will be changed so that we have a custom adapter that will convert schedule list into listview.
	    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
	    HashMap<String, String> map = new HashMap<String, String>();
	    map.put("result", "1");
	    map.put("desc", "Wake up");
	    map.put("time", "8:45 AM");
	    mylist.add(map);
	    map = new HashMap<String, String>();
	    map.put("result", "-1");
	    map.put("desc", "Breakfast");
	    map.put("time", "9:00 AM");
	    mylist.add(map);
	    map = new HashMap<String, String>();
	    map.put("result", "1");
	    map.put("desc", "Lunch");
	    map.put("time", "12:00 PM");
	    mylist.add(map);
	    map = new HashMap<String, String>();
	    map.put("result", "0");
	    map.put("desc", "Dinner");
	    map.put("time", "7:30 PM");
	    mylist.add(map);
	    map = new HashMap<String, String>();
	    map.put("result", "0");
	    map.put("desc", "Sleep");
	    map.put("time", "1:00 AM");
	    mylist.add(map);
	    SimpleAdapter scheduleAdp = new SimpleAdapter( this,mylist, R.layout.schedule_row,
	                	new String[] {"result", "desc", "time"},
	                	new int[] {R.id.cell_result, R.id.cell_desc, R.id.cell_time});
	    mScheduleList.setAdapter(scheduleAdp);
	    // -----------------------
	    
	    // New Entry button
	    mNewEntryButton = (Button) findViewById(R.id.button_new_entry);
        mNewEntryButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), AddScheduleActivity.class);
				startActivity(intent);
			}
		});
        
        // Back button
        mBackButton = (Button) findViewById(R.id.button_back);
        mBackButton.setOnClickListener(new View.OnClickListener() {
        	@Override
        	public void onClick(View v) {
        		finish();
			}
        });
	    
	}
}
